<template>
  <div>
    <van-nav-bar title="登录"></van-nav-bar>
    <form-submit @submit="submit"></form-submit>
  </div>
</template>
<script>
import formSubmit from "../../components/form-submit";
import { createNamespacedHelpers } from 'vuex';
import * as types from '../../store/action-type';
import {Dialog} from "vant";
const { mapActions } = createNamespacedHelpers('user');
export default {
  components: {
    formSubmit
  },
  methods: {
    ...mapActions([types.SET_LOGIN]),
    async submit(values) {
      try {
        await this[types.SET_LOGIN](values);
        await this.$router.push('/profile');
      } catch (e) {
        await Dialog.alert({
          title: '登录失败',
          message: e.data
        })
      }
    }
  }
}
</script>